<?php

namespace App\Admin\Extensions\Tools\Vasseti;

use Encore\Admin\Admin;
use Encore\Admin\Grid\Tools\AbstractTool;
use Illuminate\Support\Facades\Request;

class VassetiAsyncResult extends AbstractTool
{
    protected function script()
    {
        $status = Request::get('async_result') ? Request::get('async_result') : 'all';
        $url = Request::fullUrlWithQuery(['async_result' => '_async_result_', 'status' => $status]);

        return <<<EOT

$('input:radio.vasseti-async').change(function () {

    var url = "$url".replace('_async_result_', $(this).val());

    $.pjax({container:'#pjax-container', url: url });

});

EOT;
    }

    public function render()
    {
        Admin::script($this->script());
        $options = [
            'all'   => '所有',
            'on'     => '已注入',
            'off'     => '正在注入',
        ];
        return view('admin.tools.vasseti.vasseti-async', compact('options'));
    }
}